package com.th.coupon.feign.hystrix;

import com.th.coupon.common.exception.BaseCloudException;
import com.th.coupon.common.vo.CommonResponse;
import com.th.coupon.common.vo.SettlementInfo;
import com.th.coupon.feign.SettlementClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.Objects;

/**
 * 调用结算微服务的服务接口熔断降级策略 熔断兜底
 * @author 涂航
 */
@Slf4j
@Component
public class SettlementClientHystrix implements SettlementClient {

    /**
     * 优惠卷规则计算
     * @param settlementInfo {@link SettlementInfo} 结算
     * @return
     * @throws BaseCloudException
     */
    @Override
    public CommonResponse<SettlementInfo> computeRule(SettlementInfo settlementInfo) throws BaseCloudException {

        log.error("【coupon-settlement-service】 computeRule request error !!!");
        settlementInfo.setEmploy(false);
        settlementInfo.setCost(-1.0);
        return new CommonResponse<>(
                -1,
                "【coupon-settlement-service】 computeRule request error !!!",
                settlementInfo
        );
    }
}
